﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Security.Cryptography;
using System.Data;

public partial class Admin_ChangePass : System.Web.UI.Page
{
    AdminBUS adBUS = new AdminBUS();
    DataTable tbAdmin = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (txtOPassword.Text.Equals("") || txtNPassword.Text.Equals("") || txtCPassword.Text.Equals(""))
        {
            lblError.Text = "- You must enter enough information";
        }
        else
        {
            tbAdmin = adBUS.isValidLogin(Session["MemUser"].ToString(), Md5AddSecret(txtOPassword.Text));
            if (tbAdmin.Rows.Count > 0)
            {
                if (txtNPassword.Text.Equals(txtCPassword.Text))
                {
                    bool check = adBUS.updatePassword(Int32.Parse(Session["MemID"].ToString()), Md5AddSecret(txtNPassword.Text));
                    if (check)
                    {

                        lblError.Text = "";
                    }
                }
                else
                {
                    lblError.Text = "- New password must same confirm password";

                }

            }
            else
            {
                lblError.Text = "- Password wrong";

            }
        }
    }
    public string Md5AddSecret(string strChange)
    {
        //Change the syllable into UTF8 code
        byte[] pass = Encoding.UTF8.GetBytes(strChange);
        MD5 md5 = new MD5CryptoServiceProvider();
        string strPassword = Encoding.UTF8.GetString(md5.ComputeHash(pass));
        return strPassword;
    }
}